package com.sx.pipeline.repos.http

import com.sx.mvvmlibs.http.HttpRequest
import com.sx.pipeline.app.config.BaseEntity
import com.sx.pipeline.repos.http.req.*
import com.sx.pipeline.repos.http.res.*
import com.sx.pipeline.repos.http.service.*
import com.sx.pipeline.utils.kml.FileParseBean
import com.sx.pipeline.view.treeview2.OrganizeDeptRes
import io.reactivex.rxjava3.core.Observable
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import retrofit2.http.Body
import retrofit2.http.POST
import java.io.File

/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: Http数据源实现接口
 */
object HttpSourceImpl: IHttpSource {

    private var mApiService = HttpRequest.getService(IApiService::class.java)

    private var mWorkBenchService = HttpRequest.getService(IWorkBenchService::class.java)

    private var mBusinessService  = HttpRequest.getService(IBusinessService::class.java)

    private var mMapService = HttpRequest.getService(IMapService::class.java)

    private var mRongImService = HttpRequest.getService(IRongImService::class.java)

    /**
     * 获取省市区数据
     */
    override fun getProvinces(): Observable<BaseEntity<List<ProvincesVO>>> {
        return mApiService.getProvinces()
    }

    /**
     * 查询单位类型
     */
    override fun queryUnitType(identityID:Int?): Observable<BaseEntity<List<UnitTypeVO>>> {
        return mApiService.getUnitType(identityID)
    }

    /**
     * 获取单位名称列表
     */
    override fun getUnitNameList(
        name: String?,
        areaId: Int,
        typeAttribute: String?,
        unitTypeId: String?,
        identity: Int,
        isPage: Boolean,
        page: Int,
        limit: Int,
    ): Observable<BaseEntity<Ipage<UnitNameVO>>> {
        return mApiService.getUnitNameList(name, areaId, typeAttribute, unitTypeId, identity, isPage, page, limit)
    }

    override fun getRegUnitNameList(
        name: String?,
        areaId: Int,
        typeAttribute: String?,
        unitTypeId: String?,
        identity: Int,
        isPage: Boolean,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<UnitNameVO>>> {
        return mApiService.getRegUnitNameList(name, areaId, typeAttribute, unitTypeId, identity, isPage, page, limit)
    }

    /**
     * 注册发送验证码
     */
    override fun sendSmsCode(phone: String, type: Int?): Observable<BaseEntity<Boolean>> {
        return mApiService.sendSmsCode(phone, type)
    }

    override fun getAgreement(id: Long): Observable<BaseEntity<AgreementVO>> {
        return mApiService.getAgreement(id)
    }

    override fun register(dto: RegisterDTO): Observable<BaseEntity<Boolean>> {
        return mApiService.register(dto)
    }

    override fun login(dto: LoginDTO): Observable<BaseEntity<LoginVO>> {
        return mApiService.login(dto)
    }

    override fun cancelAccount(): Observable<BaseEntity<Any>> {
        return mApiService.cancelAccount()
    }

    override fun bindPhone(dto: BindPhoneDTO): Observable<BaseEntity<LoginVO>> {
        return mApiService.bindPhone(dto)
    }

    override fun modifyPassword(dto: ModifyPwdDTO): Observable<BaseEntity<Boolean>> {
        return mApiService.modifyPassword(dto)
    }


    override fun getUserInfo(): Observable<BaseEntity<UserInfoVO>> {
        return mApiService.getUserInfo()
    }

    override fun getNoticeTypeList(): Observable<BaseEntity<List<MessageTypeVo>>> {
        return mApiService.getNoticeTypeList()
    }

    override fun getNoticeByCode(code: Int,page:Int): Observable<BaseEntity<Ipage<MessageListVo>>> {
        return mApiService.getNoticeByCode(code,page)
    }

    override fun getNoticeDetail(dto: MessageDTO): Observable<BaseEntity<MessageDetailVo>> {
        return  mApiService.getNoticeDetail(dto)
    }

    override fun getTask(): Observable<BaseEntity<TaskConfigVo>> {
        return mApiService.getTask()
    }

    override fun getContacts(): Observable<BaseEntity<List<TaskContactVo>>> {
        return mApiService.getContacts()
    }

    override fun getAllHaveRead(): Observable<BaseEntity<Boolean>> {
        return mApiService.getAllHaveRead()
    }

    override fun getTaskAdd(dto: TaskAddDTO): Observable<BaseEntity<TaskGroupVO>> {
        return mApiService.getTaskAdd(dto)
    }

    override fun getNeed(): Observable<BaseEntity<TaskConfigVo>> {
        return mApiService.getNeed()
    }

    override fun uploadImage(file: File): Observable<BaseEntity<String>> {
        val builder = MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart(
                "file",
                file.name,
                file.asRequestBody("multipart/form-data".toMediaTypeOrNull())
            )
        return mApiService.uploadImage(builder.build())
    }

    override fun putTaskList(status: Int, page: Int): Observable<BaseEntity<Ipage<ReleaseTaskVo>>> {
        return mApiService.putTaskList(status, page,true,10)
    }

    override fun getCancelTask(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.getCancelTask(id)
    }

    override fun getEndTask(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.getEndTask(id)
    }

    override fun getRemoveTask(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.getRemoveTask(id)
    }

    override fun getTaskDelay(dto: TaskDelayDTO): Observable<BaseEntity<Any>> {
        return mApiService.getTaskDelay(dto)
    }

    override fun takePartTaskList(
        status: Int,
        page: Int
    ): Observable<BaseEntity<Ipage<ReleaseTaskVo>>> {
        return mApiService.takePartTaskList(status,page,true,10)
    }

    override fun auditTaskList(
        status: Int,
        page: Int
    ): Observable<BaseEntity<Ipage<ReleaseTaskVo>>> {
        return mApiService.auditTaskList(status,page,true,10)
    }

    override fun getTaskAudit(dto: AuditTaskDTO): Observable<BaseEntity<TaskGroupVO>> {
        return mApiService.getTaskAudit(dto)
    }

    override fun dealWithTask(dto: DealTaskDTO): Observable<BaseEntity<Any>> {
        return mApiService.dealWithTask(dto)
    }

    override fun getUserUnit(): Observable<BaseEntity<UserUnitVo>> {
        return mApiService.getUserUnit()
    }

    override fun getTaskDetail(id: Int): Observable<BaseEntity<TaskDetailVo>> {
        return mApiService.getTaskDetail(id)
    }

    override fun getSupply(): Observable<BaseEntity<TaskConfigVo>> {
        return mApiService.getSupply()
    }

    override fun equipmentAdd(dto: EquipmentAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.equipmentAdd(dto)
    }

    override fun getEquipmentList(
        key: String,
        page: Int
    ): Observable<BaseEntity<Ipage<DeviceInfoVo>>> {
        return mApiService.getEquipmentList(key,page,true,10)
    }

    override fun getDeviceDetail(id: Int): Observable<BaseEntity<DeviceInfoVo>> {
        return mApiService.getDeviceDetail(id)
    }

    override fun equipmentEdit(dto: EquipmentAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.equipmentEdit(dto)
    }

    override fun getEquipmentDelete(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.getEquipmentDelete(id)
    }

    override fun supplyOrderAdd(dto: SupplyOrderAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.supplyOrderAdd(dto)
    }

    override fun pushSupplyPage(
        status: Int,
        page: Int
    ): Observable<BaseEntity<Ipage<ReleaseSupplyVo>>> {
        return mApiService.pushSupplyPage(status,page,true,10)
    }

    override fun getProduct(): Observable<BaseEntity<TaskConfigVo>> {
        return mApiService.getProduct()
    }

    override fun productAdd(dto: GoodsAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.productAdd(dto)
    }

    override fun getProductList(
        key: String,
        page: Int
    ): Observable<BaseEntity<Ipage<GoodsInfoVo>>> {
        return mApiService.getProductList(key,page,true,10)
    }

    override fun productEdit(dto: GoodsAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.productEdit(dto)
    }

    override fun deleteProduct(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.deleteProduct(id)
    }

    override fun getGoodsDetail(id: Int): Observable<BaseEntity<GoodsInfoVo>> {
        return mApiService.getGoodsDetail(id)
    }

    override fun auditSupplyList(
        status: Int,
        page: Int
    ): Observable<BaseEntity<Ipage<ReleaseSupplyVo>>> {
        return mApiService.auditSupplyList(status,page,true,10)
    }

    /**
     * 轮播图
     */
    override fun getBannerList(): Observable<BaseEntity<List<BannerVO>>> {
        return mWorkBenchService.getBannerList()
    }

    /**
     * 公告以及消息数量
     */
    override fun getInformation(): Observable<BaseEntity<InformationVO>> {
        return mWorkBenchService.getInformation()
    }

    override fun getModuleList(): Observable<BaseEntity<List<CommonApplyListVO>>> {
        return mWorkBenchService.getModuleList()
    }

    override fun getSupplyAudit(dto: AuditTaskDTO): Observable<BaseEntity<Any>> {
        return mApiService.getSupplyAudit(dto)
    }

    override fun getSupplyOrderDetail(id: Int): Observable<BaseEntity<SupplyDetailVo>> {
        return mApiService.getSupplyOrderDetail(id)
    }

    override fun takePartSupplyList(
        key: String,
        page: Int,
        isPage: Boolean,
        limit: Int,
    ): Observable<BaseEntity<Ipage<ReleaseSupplyVo>>> {
        return mApiService.takePartSupplyList(key, page, isPage, limit)
    }


    override fun addInquiry(dto: AddInquiryDTO): Observable<BaseEntity<Any>> {
        return mApiService.addInquiry(dto)
    }

    override fun getInquiryList(orderId: Int): Observable<BaseEntity<List<ViewInquiryVo>>> {
        return mApiService.getInquiryList(orderId)
    }

    override fun cancelSupplyOrder(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.cancelSupplyOrder(id)
    }

    override fun deleteSupplyOrder(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.deleteSupplyOrder(id)
    }

    override fun cancelNeedOrder(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.cancelNeedOrder(id)
    }

    override fun deleteNeedOrder(id: Int): Observable<BaseEntity<Any>> {
        return  mApiService.deleteNeedOrder(id)
    }

    override fun addNeedOrder(dto: ReleaseNeedsAddDTO): Observable<BaseEntity<Int>> {
        return mApiService.addNeedOrder(dto)
    }

    override fun operationPushNeedPage(
        status: Int,
        page: Int
    ): Observable<BaseEntity<Ipage<ReleaseNeedsVO>>> {
        return mApiService.operationPushNeedPage(status,page,true,10)
    }

    override fun addConstructionNeedOrder(dto: ReleaseNeedsAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.addConstructionNeedOrder(dto)
    }

    override fun editConstructionNeedOrder(dto: ReleaseNeedsAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.editConstructionNeedOrder(dto)
    }

    override fun takePartNeedPage(
        key:String,
        page: Int,
        isPage: Boolean,
        limit: Int,
    ): Observable<BaseEntity<Ipage<ReleaseNeedsVO>>> {
        return mApiService.takePartNeedPage(key, page,isPage,limit)
    }


    override fun pushNeedPageList(
        status: Int,
        page: Int
    ): Observable<BaseEntity<Ipage<ReleaseNeedsVO>>> {
        return mApiService.pushNeedPageList(status,page,true,10)
    }

    override fun auditNeedPage(
        status: Int,
        page: Int
    ): Observable<BaseEntity<Ipage<ReleaseNeedsVO>>> {
        return mApiService.auditNeedPage(status,page,true,10)
    }

    override fun getNeedOrderAudit(dto: AuditTaskDTO): Observable<BaseEntity<Any>> {
        return mApiService.getNeedOrderAudit(dto)
    }

    override fun getNeedOrderDetail(id: Int): Observable<BaseEntity<ReleaseNeedsVO>> {
        return mApiService.getNeedOrderDetail(id)
    }

    override fun getTaskStatistics(
        taskType: Int,
        timeType: Int,
    ): Observable<BaseEntity<HashMap<Int, TaskStatisticsVO>>> {
        return mWorkBenchService.getTaskStatistics(taskType, timeType)
    }

    override fun getUndoneTask(
        taskType: Int,
        timeType: Int,
        type: Int,
        isPage: Boolean,
        page: Int,
        limit: Int,
    ): Observable<BaseEntity<Ipage<ReleaseTaskVo>>> {
        return mWorkBenchService.getUndoneTask(taskType, timeType, type, isPage, page, limit)
    }

    override fun getUnitIdentity(): Observable<BaseEntity<List<IdentityVO>>> {
        return mBusinessService.getUnitIdentity()
    }

    override fun applyIdentity(identity: String): Observable<BaseEntity<Any>> {
        return mBusinessService.applyIdentity(identity)
    }

    override fun getSwitchUnitList(): Observable<BaseEntity<List<MyUnitListVO>>> {
        return mBusinessService.getSwitchUnitList()
    }

    override fun switchUnitIdentity(identity: String, unitId: Int): Observable<BaseEntity<IdentityVO>> {
        return mBusinessService.switchUnitIdentity(identity, unitId)
    }

    override fun joinBusiness(dto: JoinBusinessDTO): Observable<BaseEntity<Any>> {
        return mBusinessService.joinBusiness(dto)
    }

    override fun getLearningStudy(
        isPage: Boolean,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<StudyCenterVO>>> {
        return mApiService.getLearningStudy(page, isPage, limit)
    }

    override fun updateUser(dto: ResetUserDTO): Observable<BaseEntity<Any>> {
        return mApiService.updateUser(dto)
    }

    override fun getAdvertiseList(
        isPage: Boolean,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<AdvertiseVO>>> {
        return mApiService.getAdvertiseList(page, isPage, limit)
    }



    override fun addQuotedPrice(dto: AddQuotedPriceDTO): Observable<BaseEntity<Any>> {
        return mApiService.addQuotedPrice(dto)
    }

    override fun getQuotedPrice(id: Int): Observable<BaseEntity<List<NeedsQuotedVO>>> {
        return mApiService.getQuotedPrice(id)
    }

    override fun addTaskEvaluate(dto: List<TaskEvaluateDTO>): Observable<BaseEntity<Any>> {
        return mApiService.addTaskEvaluate(dto)
    }

    override fun getEvaluate(id: Int): Observable<BaseEntity<List<TaskEvaluateVO>>> {
        return  mApiService.getEvaluate(id)
    }

    override fun getPmsServiceList(
        key: String,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<ServiceAddDTO>>> {
     return mApiService.getPmsServiceList(key,page,true,limit)
    }

    override fun getServiceTitle(): Observable<BaseEntity<List<ServiceTitleVO>>> {
        return mApiService.getServiceTitle()
    }

    override fun addServiceDevice(dto: ServiceAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.addServiceDevice(dto)
    }

    override fun editServiceDevice(dto: ServiceAddDTO): Observable<BaseEntity<Any>> {
        return mApiService.editServiceDevice(dto)
    }

    override fun getServiceDelete(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.getServiceDelete(id)
    }

    override fun getServiceDeviceDetail(id: Int): Observable<BaseEntity<ServiceAddDTO>> {
        return mApiService.getServiceDeviceDetail(id)
    }

    override fun addFeedback(content: String): Observable<BaseEntity<Any>> {
        return mApiService.addFeedback(content)
    }

    override fun getAppVersion(): Observable<BaseEntity<VersionUpdateVO>> {
        return mApiService.getAppVersion()
    }

    override fun getAdvertisingDetail(
        unitId: Int,
        page: Int
    ): Observable<BaseEntity<AdvertiseDetailVO>> {
        return mApiService.getAdvertisingDetail(unitId,page,true,10)
    }

    override fun getSupplyPrice(
        serverId: Int,
        startTime: String,
        endTime: String
    ): Observable<BaseEntity<Double>> {
        return mApiService.getSupplyPrice(serverId,startTime, endTime)
    }

    override fun addBankCard(dto: AddBankDTO): Observable<BaseEntity<Any>> {
        return mApiService.addBankCard(dto)
    }

    override fun getBankCardList(
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<BankListVO>>> {
        return mApiService.getBankCardList(page,true,limit)
    }

    override fun deleteBank(id: Int): Observable<BaseEntity<Any>> {
        return mApiService.deleteBank(id)
    }

    override fun getWalletBillList(
        income: String,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<BalanceRecordVO>>> {
        return mApiService.getWalletBillList(income,page,true,limit)
    }

    override fun getWithdraw(dto: WithdrawDTO): Observable<BaseEntity<Any>> {
        return mApiService.getWithdraw(dto)
    }

    override fun findWithdrawByPage(
        status: Int,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<WithdrawRecordVO>>> {
        return mApiService.findWithdrawByPage(status,page,true,limit)
    }

    override fun getNeedPrice(): Observable<BaseEntity<Double>> {
        return mApiService.getNeedPrice()
    }

    override fun getRechargeList(): Observable<BaseEntity<List<RechargeInfoVO>>> {
        return mApiService.getRechargeList()
    }

    override fun sumitWxRecharge(id:Int): Observable<BaseEntity<WechatResponse>> {
        return mApiService.sumitWxRecharge(id)
    }

    override fun getAdvertisingIntro(id: Int): Observable<BaseEntity<AgreementVO>> {
        return mApiService.getAdvertisingIntro(id)
    }

    override fun getRongContact(name:String): Observable<BaseEntity<List<ContactUserVo>>> {
        return mRongImService.getRongContact(name)
    }

    override fun getRongContact(
        groupId: String,
        userName: String
    ): Observable<BaseEntity<List<ContactUserVo>>> {
        return mRongImService.getContactList(groupId,userName)
    }

    override fun getRyPersonalInfo(id: Int): Observable<BaseEntity<RyUserVo>> {
        return mRongImService.getRyPersonalInfo(id)
    }

    override fun getRongOrganize(): Observable<BaseEntity<List<OrganizeDeptRes>>> {
        return mRongImService.getRongOrganize()
    }

    override fun getCreateGroup(dto: CreateGroupDTO): Observable<BaseEntity<Any>> {
        return mRongImService.getCreateGroup(dto)
    }

    override fun getTaskCreateGroup(dto: TaskCreateGroupDTO): Observable<BaseEntity<Any>> {
        return mRongImService.getTaskCreateGroup(dto)
    }

    override fun getRongGroupList(): Observable<BaseEntity<List<RongGroupVO>>> {
        return mRongImService.getRongGroupList()
    }

    override fun getRongAllContact(): Observable<BaseEntity<List<ContactUserVo>>> {
        return mRongImService.getRongAllContact()
    }

    /**
     * 地图模块
     */
    override fun addTerritory(dto: FileParseBean): Observable<BaseEntity<Any>> {
        return mMapService.addTerritory(dto)
    }

    override fun getTerritoryList(
        type: Int,
        page: Int,
        limit: Int,
        isPage: Boolean,
    ): Observable<BaseEntity<Ipage<TerritoryVO>>> {
        return mMapService.getTerritoryList(type, page, limit, isPage)
    }

    override fun deleteTerritory(ids: Long): Observable<BaseEntity<Any>> {
        return mMapService.deleteTerritory(ids)
    }

    override fun addDistrictBorder(dto: DistrictBorderDTO): Observable<BaseEntity<Any>> {
        return mMapService.addDistrictBorder(dto)
    }

    override fun getDistrictBorderList(
        page: Int,
        limit: Int,
        isPage: Boolean
    ): Observable<BaseEntity<Ipage<DistrictBorderDTO>>> {
        return mMapService.getDistrictBorderList(page, limit, isPage)
    }

    override fun deleteDistrictBorder(ids: Long): Observable<BaseEntity<Any>> {
        return mMapService.deleteDistrictBorder(ids)
    }

    override fun getInquiryPrice(): Observable<BaseEntity<Double>> {
        return mApiService.getInquiryPrice()
    }

    override fun getNeedQuote(): Observable<BaseEntity<Double>> {
        return mApiService.getNeedQuote()
    }

    override fun requestJoinGroup(id:Int): Observable<BaseEntity<Any>> {
        return mApiService.requestJoinGroup(id)
    }

    override fun addAdministrative(dto: AddAdministrativeDTO): Observable<BaseEntity<Any>> {
        return mApiService.addAdministrative(dto)
    }

    override fun getAppServiceId(): Observable<BaseEntity<ContactUserVo>> {
        return mApiService.getImId()
    }

    override fun getExamineOperatorList(
        status: Int,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<ExamineOperatorVo>>> {
        return mApiService.getExamineOperatorList(status, page, limit)
    }

    override fun getExamineRecordList(
        status: Int,
        page: Int,
        limit: Int
    ): Observable<BaseEntity<Ipage<ExamineRecordVo>>> {
        return mApiService.getExamineRecordList(status, page, limit)
    }

    override fun audit(id: Int, status: Int, remark: String?): Observable<BaseEntity<Any>> {
        return mApiService.audit(AuditDTO(id, status, remark))
    }

    override fun applyInfo(id: String): Observable<BaseEntity<ExamineInfoVo>> {
        return mApiService.applyInfo(id)
    }

    override fun groupListInfo(id: String):Observable<BaseEntity<GroupDetailVo>> {
        return mRongImService.groupListInfo(id)
    }

    override fun exitGroup(id: Int): Observable<BaseEntity<Any>> {
        return mRongImService.exitGroup(id.toString())
    }

    override fun addGroup(groupId: String, userIds: String): Observable<BaseEntity<Any>> {
        return mRongImService.addGroup(groupId, userIds)
    }

    override fun quitGroup(groupId: String, userIds: String): Observable<BaseEntity<Any>> {
        return mRongImService.quitGroup(groupId, userIds)
    }

    override fun cleanGroup(groupId: Int): Observable<BaseEntity<Any>> {
        return mRongImService.cleanGroup(groupId.toString())
    }

    override fun groupReport(dto : ReqGroupReportDTO): Observable<BaseEntity<Any>>{
        return mApiService.groupReport(dto)
    }

    override fun userReport(dto : ReqUserReportDTO): Observable<BaseEntity<Any>>{
        return mApiService.userReport(dto)
    }

    override fun submitAliPayRecharge(rechargeId: Int): Observable<BaseEntity<String>> {
        return mApiService.submitAliPayRecharge(AliPayRechargeReq(rechargeId))
    }
}